function User(name){
  return {name:name}
}

// var singleUser = (function(){
//   var result;
//   return function(name){
//     return result || (result = {name:name})
//   }
// })();
// console.log(singleUser("tom").name)
//
// console.log(singleUser("jack").name)


var makeSingle = function(constructor){
  var result;
  return {
    create: function(){
      return result || (result = constructor.apply(this,arguments));
    },
    remove: function(){
      result = null
    }
  }
}


var singleUser = makeSingle(User)
var tom = singleUser.create("tom")
singleUser.create("jack")

console.log(tom.name)
singleUser.remove()
tom = singleUser.create("jerry")
console.log(tom.name)
